//
//  CreateGroupViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/4/5.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "CreateGroupViewController.h"
#import "AddGroupImageViewController.h"

@interface CreateGroupViewController ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *groupTF; // 小组姓名
@property (nonatomic, assign) CGFloat tempShu;

@end

@implementation CreateGroupViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    // navi的修改
    [self changeNavigation];
    // 布局
    [self addMySubview];
}

// navi的修改
- (void)changeNavigation
{
    [self.navigationController.navigationBar setTranslucent:NO];
    self.navigationItem.title = @"填写小组名称";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStylePlain target:self action:@selector(nextPage:)];
    rightItem.tintColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 下一步
- (void)nextPage:(UIBarButtonItem *)rightItem
{
    [self.groupTF resignFirstResponder];
     self.groupTF.text = @"请填写小组名称 (至少输入两个字符)";
    AddGroupImageViewController *addGroupImageV = [[AddGroupImageViewController alloc] init];
    [self.navigationController pushViewController:addGroupImageV animated:YES];
}

#pragma mark - 布局
- (void)addMySubview
{
    UIImageView *groupTopImageV = [[UIImageView alloc] initWithFrame:CGRectMake(-1 * kAdjustParamater, - 1 * kAdjustParamater, kScreenWidth + 2 * kAdjustParamater, 370 * kAdjustParamater)];
   // groupTopImageV.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.3];
    groupTopImageV.image = [UIImage imageNamed:@"groupName-tianjia"];
    [self.view addSubview:groupTopImageV];
    
    // 小组姓名
    self.groupTF = [[UITextField alloc] initWithFrame:CGRectMake(17 * kAdjustParamater, groupTopImageV.bottom + 13 * kAdjustParamater, 300 * kAdjustParamater, 20 * kAdjustParamater)];
    self.groupTF.text = @"请填写小组名称 (至少输入两个字符)";
    self.groupTF.textColor = kCyanColor;
    self.groupTF.textAlignment = NSTextAlignmentLeft;
    self.groupTF.delegate = self;
    self.groupTF.clearsOnBeginEditing = YES;
    self.groupTF.font = [UIFont systemFontOfSize:k14Big];
    [self.groupTF addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventAllEditingEvents];
    [self.view addSubview:_groupTF];

    
    // 小组名字下方的浅色条
    UILabel *cyanLine = [[UILabel alloc] initWithFrame:CGRectMake(0, self.groupTF.bottom + 13 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
    cyanLine.backgroundColor = kCyanColor;
    [self.view addSubview:cyanLine];
}

- (void)valueChange:(UITextField *)tempText
{
    NSLog(@"textField = %@", tempText.text);
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [UIView animateWithDuration:0.2 animations:^{
        //self.view.transform = CGAffineTransformMakeTranslation(0, offsetY);
        self.view.transform = CGAffineTransformMakeTranslation(0, 0);
    }];
    if (textField.text.length == 0) {
        textField.text = @"请填写小组名称 (至少输入两个字符)";
    }
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
    [UIView animateWithDuration:0.2 animations:^{
        //self.view.transform = CGAffineTransformMakeTranslation(0, offsetY);
        self.view.transform = CGAffineTransformMakeTranslation(0, -94 * kAdjustParamater);
    }];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
